package com.shujia;

import org.apache.flink.table.api.EnvironmentSettings;
import org.apache.flink.table.api.TableEnvironment;

public class FLinkSqlRun {
    public static void main(String[] args) {

        if (args.length == 0) {
            System.out.println("请指定执行的sql");
            return;
        }
        String sqlStr = args[0];
        System.out.println("===========================================================");
        System.out.println(sqlStr);
        System.out.println("===========================================================");
        //1、创建flink sql执行环境
        //传概念配置对象
        EnvironmentSettings settings = EnvironmentSettings
                .newInstance()
                .inStreamingMode()//流处理模式
                //.inBatchMode()//批处理模式
                .build();

        //创建环境
        TableEnvironment tEnv = TableEnvironment.create(settings);

        //解析sql
        String[] sqls = sqlStr.split(";");

        //循环执行sql
        for (String sql : sqls) {
            if (sql.trim().length() != 0) {
                tEnv.executeSql(sql);
            }
        }
    }
}
